<?php
/**
 * 类的创建
 */
class Product {

}

$p1 = new Product();
$p2 = new Product();

// var_dump($p1, $p2);

// class ShopProduct {
// 	public $title        = '商品名称';
// 	public $producerName = '制造商名称';
// 	public $place        = '产地';
// 	public $price        = 0;
// 	private $discount    = 0;
// 	protected $sell      = 1;

// 	function __construct($title, $producerName, $place, $price) {
// 		$this->title        = $title;
// 		$this->producerName = $producerName;
// 		$this->place        = $place;
// 		$this->price        = $price;
// 	}

// 	function getProducer() {
// 		return "$this->place" . "$this->producerName";
// 	}
// }

// $p3 = new ShopProduct('人字拖', '浙江美大', '东阳', 35);

// $p3->title        = '人字拖';
// $p3->producerName = '浙江美丽';
// $p3->place        = '东阳';
// $p3->price        = 35;
// $p3->code = '121132323';
// echo $p3->title, $p3->code;
// echo '<br />';
// echo $p3->price;
// echo '<br />';
// echo $p3->getProducer();
// echo '<br />';

class StaticExample {
	static public $siteName = '';
	public $siteUrl         = 'www.xbmu.edu.cn';
	static public function sayHello() {
		echo 'hello';
		// 静态方法不能访问这个类中的普通属性
		// echo $this->siteurl;
	}
	static public function setSiteName($str = '西北民族大学') {
		// 在类内部，可以使用self关键字访问当前类
		self::$siteName = $str;
		echo self::$siteName;
	}
}

// 静态属性及方法的访问
// echo StaticExample::$siteName;
// StaticExample::sayHello();
// StaticExample::setSiteName();
// // echo StaticExample::$siteName;

// $se = new StaticExample();

// // 不能在对象中调用静态方法和属性
// echo $se->siteName;
// var_dump($se);
// $se->sayHello();
//
//
//
class ShopProduct {
	public $title        = '商品名称';
	public $producerName = '制造商名称';
	public $place        = '产地';
	public $price        = 0;
	private $discount    = 0.9;

	function __construct($title, $producerName, $place, $price) {
		$this->title        = $title;
		$this->producerName = $producerName;
		$this->place        = $place;
		$this->price        = $price;
	}
	function getProducer() {
		return "$this->place" . "$this->producerName";
	}
	function getSummaryLine() {
		$base = "$this->title" . "\t" . "$this->place" . "\t" . "$this->producerName";
		return $base;
	}
}

//继承父类使用extends关键词

class BookProduct extends ShopProduct {
	public $numPages;
	public $author;

	//构造函数
	function __construct($title, $producerName, $place, $price, $numPages, $author) {
		parent::__construct($title, $producerName, $place, $price); //直接调用父类的方法，减少重复代码
		$this->numPages = $numPages;
		$this->author   = $author;
	}
	//子类自有方法
	function getNumPages() {
		return $this->numPages;
	}
	function getAuthor() {
		return $this->author;
	}
	function getSummaryLine() {
		$base = parent::getSummaryLine();
		$base .= "\t" . "$this->numPages" . "\t" . "$this->author";
		return $base;
	}
}

class PhoneProduct extends ShopProduct {
	public $brand;
	public $os;

	//构造函数
	function __construct($title, $producerName, $place, $price, $brand, $os) {
		//直接调用父类的方法，减少重复代码
		parent::__construct($title, $producerName, $place, $price);
		$this->brand = $brand;
		$this->os    = $os;
	}
	//子类自有方法
	function getBrand() {
		return $this->brand;
	}
	function getOs() {
		return $this->os;
	}
	function getSummaryLine() {
		$base = parent::getSummaryLine();
		$base .= "\t" . "$this->brand" . "\t" . "$this->os";
		return $base;
	}
}

$book1  = new BookProduct("信息简史", "人民邮电出版社", "北京", 69, 458, "詹姆斯·格雷克");
$phone1 = new PhoneProduct("荣耀3C", "华为公司", "深圳", 999, "huawei", "android 4.2");

echo $book1->getSummaryLine();
echo $book1->discount();
echo "<br />";
echo $phone1->getSummaryLine();
echo "<br />";
echo $phone1->getOs();
?>
